/**
 * 根据流下载文件
 * @param {*} d  
 * @param {string} name 
 */
export const downByBlob = (d, name: string): void => {
    const binaryData: any = [d];
    const url = window.URL.createObjectURL(new Blob(binaryData));
    const link = document.createElement('a');
    if (link.download !== undefined) {
        link.download = name;
    }
    if (document.createEvent) {
        const e = document.createEvent('MouseEvents');
        e.initEvent('click', true, false);
        link.href = url;
        link.dispatchEvent(e);
        window.URL.revokeObjectURL(url);
    }
};

/**
 * 根据url下载文件
 * @param fileName 
 * @param url 
 */
export const downByUrl = (fileName: string, url: string) => {
    const link = document.createElement('a');
    const evt = document.createEvent('MouseEvents');
    // var evt = document.createEvent("HTMLEvents")
    evt.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    link.download = fileName;
    link.href = url;
    link.dispatchEvent(evt);
};